<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function par(nums) {
      const n = nums.length;
      let leftM = nums[0],
        leftP = 0,
        curM = nums[0];
      for (let i = 1; i < n - 1; i++) {
        curM = Math.max(curM, nums[i]);
        if (nums[i] < leftM) {
          leftM = curM;
          leftP = i;
        }
      }
      return leftP + 1;
    };
    console.log(par([5, 0, 3, 8, 6]));
  </script>
</body>

</html>